﻿// CDialogPen.cpp: 实现文件
//

#include "pch.h"
#include "comAPP2.h"
#include "CDialogPen.h"
#include "afxdialogex.h"


// CDialogPen 对话框

IMPLEMENT_DYNAMIC(CDialogPen, CDialogEx)

CDialogPen::CDialogPen(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_PEN_DIALOG, pParent)
{

}

CDialogPen::~CDialogPen()
{
}

void CDialogPen::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_PEN_WIDTH, EditPenWidth);
	DDX_Control(pDX, IDC_COMBO_PENSTYLE, ComboPenStyle);
}


BEGIN_MESSAGE_MAP(CDialogPen, CDialogEx)
	ON_BN_CLICKED(IDC_SET_PENCOLOR, &CDialogPen::OnClickedSetPencolor)
	ON_BN_CLICKED(IDOK, &CDialogPen::OnBnClickedOk)
END_MESSAGE_MAP()


// CDialogPen 消息处理程序


void CDialogPen::OnClickedSetPencolor()
{
	// TODO: 在此添加控件通知处理程序代码
	CColorDialog dialog;
	if (dialog.DoModal() == IDOK)
	{
		penSetColor = dialog.GetColor();
	}
}


BOOL CDialogPen::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化

	//显示当前线宽
    char TempStr[50] = { 0 };
	wsprintf(TempStr, "%d", currentPenWidth);
	EditPenWidth.SetWindowTextA(TempStr);

	//显示当前线形（添加一些选项到Combobox中）
	ComboPenStyle.AddString(_T("直线"));
	ComboPenStyle.AddString(_T("虚线"));
	ComboPenStyle.AddString(_T("点"));
	// 设置默认选项（索引从0开始）
	if (currentPenStyle == PS_SOLID)  //直线
	{
		ComboPenStyle.SetCurSel(2);  
	}
	else if (currentPenStyle == PS_DASH) //虚线
	{
		ComboPenStyle.SetCurSel(1);
	}
	else if (currentPenStyle == PS_DOT)      //点
	{
		ComboPenStyle.SetCurSel(0);
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}



void CDialogPen::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	//获取修改后的颜色
	currentPenColor = penSetColor;
	
	//获取修改后的文本宽度
	CString tempStr;
	EditPenWidth.GetWindowTextA(tempStr);
	sscanf_s(tempStr,"%d",&currentPenWidth);

	//获取修改后的画笔样式
	//获取这个复选下拉框的索引
	int CurSel = ComboPenStyle.GetCurSel();
	if (CurSel == 2)
	{
		currentPenStyle = PS_SOLID;
	}
	else if (CurSel == 1)
	{
		currentPenStyle = PS_DASH;
	}
	else if (CurSel == 0)
	{
		currentPenStyle = PS_DOT;
	}
	CDialogEx::OnOK();
}


